/*
Copyright 2025 PerfXLab (Beijing) Technologies Co., Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "OpenSparseBLAS_func.h"
#include "OpenSparseBLAS_type.h"
#include "OpenSpB_Matrix.h"
#include <stdio.h>

void print_Vector_BOOL(OpenSpB_vector v)
{
    printf("================================\n");
    OpenSpB_index n;
    OpenSpB_vector_nvals(&n, v);
    bool value;
    printf("The vector size is %lu\n", n);
    printf("The vector elements : \n");
    for (OpenSpB_index i = 0; i < n; ++i)
    {
        value = false;
        OpenSpB_vector_extract_element_BOOL(&value, v, i);
        printf("%d ", value);
    }
    printf("\n");
    printf("================================\n");
}

void print_Vector_INT32(OpenSpB_vector v)
{
    printf("================================\n");
    OpenSpB_index n;
    OpenSpB_vector_nvals(&n, v);
    int value;
    printf("The vector size is %lu\n", n);
    printf("The vector elements : \n");
    for (OpenSpB_index i = 0; i < n; ++i)
    {
        OpenSpB_vector_extract_element_INT32(&value, v, i);
        printf("%d ", value);
    }
    printf("\n");
    printf("================================\n");
}

void print_Vector_FP32(OpenSpB_vector v)
{
    printf("================================\n");
    OpenSpB_index n;
    OpenSpB_vector_nvals(&n, v);
    float value;
    printf("The vector size is %lu\n", n);
    printf("The vector elements : \n");
    for (OpenSpB_index i = 0; i < n; ++i)
    {
        OpenSpB_vector_extract_element_FP32(&value, v, i);
        printf("%f ", value);
    }
    printf("\n");
    printf("================================\n");
}

void print_Matrix_INT32(OpenSpB_matrix m)
{
    OpenSpB_index n_row, n_col;
    OpenSpB_matrix_nrows(&n_row, m);
    OpenSpB_matrix_ncols(&n_col, m);
    printf("================================\n");
    printf("The Matrix size is: %lux%lu\n", n_row, n_col);
    printf("The matrix elements:\n");

    for (OpenSpB_index i = 0; i < n_row; ++i)
    {
        for (OpenSpB_index j = 0; j < n_col; ++j)
        {
            int32_t value = 0;
            OpenSpB_info info = OpenSpB_matrix_extract_element_INT32(&value, m, i, j);
            if (info == OpenSpB_no_value)
                value = 0;
            printf("%d ", value);
        }
        printf("\n");
    }
    printf("================================\n");
}

void print_Matrix_FP32(OpenSpB_matrix m)
{
    OpenSpB_index n_row, n_col;
    OpenSpB_matrix_nrows(&n_row, m);
    OpenSpB_matrix_ncols(&n_col, m);
    printf("================================\n");
    printf("The Matrix size is: %lux%lu\n", n_row, n_col);
    printf("The matrix elements:\n");

    for (OpenSpB_index i = 0; i < n_row; ++i)
    {
        for (OpenSpB_index j = 0; j < n_col; ++j)
        {
            float value = 0;
            OpenSpB_info info = OpenSpB_matrix_extract_element_FP32(&value, m, i, j);
            if (info == OpenSpB_no_value)
                value = 0;
            printf("%f ", value);
        }
        printf("\n");
    }
    printf("================================\n");
}

void print_Matrix_BOOL(OpenSpB_matrix m)
{
    OpenSpB_index n_row, n_col;
    OpenSpB_matrix_nrows(&n_row, m);
    OpenSpB_matrix_ncols(&n_col, m);
    printf("================================\n");
    printf("The Matrix size is: %lux%lu\n", n_row, n_col);
    printf("The matrix elements:\n");

    for (OpenSpB_index i = 0; i < n_row; ++i)
    {
        for (OpenSpB_index j = 0; j < n_col; ++j)
        {
            bool value = 0;
            OpenSpB_info info = OpenSpB_matrix_extract_element_BOOL(&value, m, i, j);
            if (info == OpenSpB_no_value)
                value = false;
            printf("%d ", value==0? 0 : 1);
        }
        printf("\n");
    }
    printf("================================\n");
}

// void print_Matrix_CSR(OpenSpB_matrix_CSR *m, int n)
// {
//     printf("================================\n");
//     printf("val :");
//     for (OpenSpB_index i = 0; i < n; i++)
//     {
//         printf("%c ", m->val[i]);
//     }
//     printf("\n");

//     printf("col :");
//     for (OpenSpB_index i = 0; i < n; i++)
//     {
//         printf("%lu ", m->col[i]);
//     }
//     printf("\n");

//     printf("ptr :");
//     for (OpenSpB_index i = 0; i <= n; i++)
//     {
//         printf("%lu ", m->ptr[i]);
//     }
//     printf("\n");

//     printf("================================\n");
// }